﻿/*
    Add to .browser
 	<!--IE fix for png images-->
	<browser id="IE6" parentID="IE6to9">
		<identification>
			<capability name="majorversion" match="6" />
		</identification>
		<controlAdapters>
			<adapter controlType="System.Web.UI.WebControls.Image" adapterType="Enterprise.Adapters.ImageControlAdapter" />
		</controlAdapters>
	</browser>
 
 
 */



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.Adapters;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Enterprise.Adapters
{
    /// <summary>
    /// Makes all IE6 png images transparent
    /// Requires image: "~/images/controls/spacer.gif"
    /// </summary>
    public class ImageControlAdapter : WebControlAdapter
    {
        protected override void Render(HtmlTextWriter writer)
        {
            Image oImage = Control as Image;
            string strPath = Page.MapPath(oImage.ImageUrl);

            // If not a PNG...
            if (!strPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase) && oImage.Attributes["PNG"] != "true")
            {
                base.Render(writer); // Have control render itself
                return;
            }

            // Setup the filter 
            string strImageUrl = oImage.ImageUrl;

            //Apply style to the image
            oImage.Style.Add(HtmlTextWriterStyle.Filter, "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Page.ResolveClientUrl(strImageUrl) + "', sizingMethod='image')");

            // Replace the image with a 1 x 1 transparent gif
            oImage.ImageUrl = Page.ResolveClientUrl("~/Images/controls/spacer.gif");
            base.Render(writer); // Have control render itself
        }
    }
}
